home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7441 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  64 lines

  1. Path: emerald.tufts.edu!rdorich
  2. From: rdorich@emerald.tufts.edu (Roberto Dorich)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: hex to dec function?
  5. Date: 26 Feb 1996 17:13:46 GMT
  6. Organization: Tufts University
  7. Message-ID: <4gspoa$pp5@d2.tufts.edu>
  8. References: <4gdh1b$bg@mailhost.mwmicro.com>  <Pine.SV4.3.91-heb-2.04.960224052121.13512E-100000@cs.technion.ac.il>
  9. NNTP-Posting-Host: emerald.tufts.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Or just use my favourite all purpose converter, sscanf().  Something
  13. like this works:
  14.  
  15. char *hex = "0x11";
  16. int  num;
  17.  
  18. sscanf(hex,"0x%x",&num);
  19.  
  20. --> num contains 17 as expected.
  21.  
  22. And of course you can go the other way too, using it's counterpart
  23. sprintf().
  24.  
  25. Good luck
  26.  
  27. Roberto
  28.  
  29. Kohn Emil Dan (emild@cs.technion.ac.il) wrote:
  30.  
  31.  
  32. : On Tue, 20 Feb 1996 aschlies@citynet.net wrote:
  33.  
  34. : > Hi There,
  35. : > 
  36. : > Is there a function that converts HEX to Dec in ANSI C?
  37. : > 
  38. : > Why re-invent the wheel?
  39. : > 
  40. : > Thanks
  41. : > Tony
  42. : > 
  43. : > 
  44. : > 
  45.  
  46.  
  47. : Try strtol();
  48.  
  49.  
  50. : Hope this helps.
  51.  
  52.  
  53. :                             Regards,
  54.  
  55.  
  56. :                                     Emil
  57.  
  58. --
  59.  
  60. Roberto Dorich               o       SKI        rdorich@ee.cornell.edu
  61. Electrical Engineering   /=     EXTREME         rdorich@tufts.edu
  62. Cornell University     __/__,               dorich@ptc.com
  63. ----------------------------------------------------------------------
  64.